package kr.dhe.gugudan.tu01_gugudan_twonine;

import java.util.Random;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Ball {
	int x; //볼 터치
	int y;
	int rad;
	
	int dx;
	int dy;
	
	int color;	//색
	int count;	//벽에 부딪친 횟수
	public Ball(int x, int y){
		Random rnd = new Random();
		this.x = x;
		this.y = y;
		this.rad = rnd.nextInt(26)+25;
		this.count = 0;
		this.color = Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
		do{
			this.dx = rnd.nextInt(11) - 5;
			this.dy = rnd.nextInt(11) - 5;
		}while(this.dx == 0 || this.dy == 0);
	}
	
	/*static Ball Create(int x,int y){
		Random rnd = new Random();
		Ball newBall = new Ball();
		
		newBall.x = x;
		newBall.y = y;
		newBall.rad = rnd.nextInt(26)+25;  //볼의 사이즈
		
		do{
			newBall.dx=rnd.nextInt(11)-5;
			newBall.dy=rnd.nextInt(11)-5;
			
		
		}while(newBall.dx == 0 || newBall.dy == 0);
	
		newBall.count = 0;
		newBall.color = Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
		
		return newBall;
	}*/
	void Move(int Width,int Height){	//화면 사이즈를 매개변수로 받음
		x +=dx;
		y +=dy;
		
		if(x<rad || x>Width-rad){
			dx *= -1; //반대방향  전환
			count++;
		}
		if(y<rad|| y>Height-rad){
			dy*=-1;
			count++;
		}
	}
	void Draw(Canvas canvas){
		Paint pnt = new Paint();
		pnt.setAntiAlias(true);
		
		for(int r=rad,alpha=1; r>4; r--,alpha+=5){
			pnt.setColor(Color.argb(alpha,
					Color.red(color), 
					Color.blue(color), 
					Color.green(color)
					)
				);
			canvas.drawCircle(x, y, r, pnt);
		}
	}

}

